
#include<iostream>
#include<vector>
using namespace std;

//高精度相加
string addinteger(const  string&s1,  const string &s2)
{
    //string s1, s2;
   // cin >> s1 >> s2;
    string ret;
    int i = s1.size() - 1; int j = s2.size() - 1;
    int carry = 0;
    while (carry || i>=0 || j>=0)
    {
        if (i >= 0)carry += (s1[i--] - '0');
        if (j >= 0)carry += (s2[j--] - '0');
        ret += carry % 10+'0';
        carry /= 10;
    }
    reverse(ret.begin(), ret.end());
    return ret;
}
//高精度相乘
string mulinteger(string s1, string s2)
{

    int flag = 1;
    if (s1[0] == '-' && s2[0] == '-')flag = 1;
    else if (s1[0] == '-' || s2[0] == '-') {
        flag = -1;
    }
    else
    {
        flag = 1;
    }
    //转化为正整数
    if (s1[0] == '-')s1.erase(s1.begin());
    if (s2[0] == '-')s2.erase(s2.begin());
    reverse(s1.begin(), s1.end());
    reverse(s2.begin(), s2.end());
    // cout << s1.size() << endl<<s2.size();  
    vector<int>ans(s1.size() + s2.size());

    for (int i = 0; i < s1.size(); ++i)
    {
        for (int j = 0; j < s2.size(); j++)
        {
            ans[i + j] += (s1[i] - '0') * (s2[j] - '0');//得到结果数组
        }
    }

    //处理进位
    int carry = 0;
    int i = 0;
    string ret;
    while (carry || i < ans.size())
    {
        carry += ans[i];
        ret += carry % 10 + '0';
        carry /= 10;
        ++i;
    }

    //处理前导零
    while (ret.size() > 1 && ret.back() == '0')ret.pop_back();
    //判断正负
    if (flag == -1)ret += '-';
    reverse(ret.begin(), ret.end());
    return ret;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    string addret = addinteger("123456789","123465789");
    string mulret = mulinteger("-123456789", "-123465789");
    cout << "高精度加法:" << addret << endl;    
    cout << "高精度乘法:" << mulret << endl;     
    return 0;
}
